/*
 * FNISVGEditor - JavaScript - based editor for SVG graphics 
 * Copyright (C) 2008 - 2009 Antti Leppä / Foyt
 * http://www.foyt.fi
 * 
 * License: 
 * 
 * Licensed under GNU Lesser General Public License Version 2.1 or later (the "LGPL") 
 * http://www.gnu.org/licenses/lgpl.html
 */
FNISVGEditorStatusInfoPlugin = Class.create(FNISVGEditorPlugin, {
  initialize : function($super, editorInstance, pluginURL) {
    $super(editorInstance, pluginURL);
    this._selectionInfoGroup = this.getEditorInstance().getStatusBar().getGroup("selectioninfo");
    if (this._selectionInfoGroup) {
      editorInstance.getSelectionManager().addListener("selectionChanged", this, this._updateStatus);
      editorInstance.getSelectionManager().addListener("selectionModeChanged", this, this._updateStatus);
      this._setSelectionInfoText(SVGLocale.getText("statusInfoPlugin_noObjectsSelected"));
    }
  },
  getName : function() {
    return "statusinfo";
  },
  _updateStatus : function(event) {
    var selectionMan = this.getEditorInstance().getSelectionManager();
    var text = '';
    var elements = selectionMan.getSelectedElements();
    if (elements.length == 0) {
      text = SVGLocale.getText("statusInfoPlugin_noObjectsSelected");
    } else {
      /* TODO: Localize typenames */
      var types = new Array();
      for ( var i = 0; i < elements.length; i++) {
        var tagName = SVGLocale.getText("elementType" + elements[i].tagName.toUpperCase());
        if (types.indexOf(tagName) == -1)
          types.push(tagName);
      }
      text = SVGLocale.getText("statusInfoPlugin_objectsSelected", elements.length, types);
    }

    this._setSelectionInfoText(text);
  },
  _setSelectionInfoText : function(text) {
    if (this._selectionInfoGroup)
      this._selectionInfoGroup.setText(text);
  }
});
document.fire("svgEditorPluginLoaded:statusinfo", {
  pluginClass : FNISVGEditorStatusInfoPlugin
});
